<?php
/**
 * Created by PhpStorm.
 * User: WenQing
 * Date: 2017/7/25
 * Time: 15:35
 */
echo "<pre>";
$fp = fsockopen("www.test.com", 80, $errno, $errstr, 30);
if (!$fp) {
    echo "$errstr ($errno)<br />\n";
} else {
    $out = "GET /php.php HTTP/1.1\r\n";
    $out .= "Host: www.test.com\r\n";
    $out .= "Connection: Close\r\n\r\n";
//    fwrite($fp, $out);
//    while (!feof($fp)) {
//        echo fgets($fp, 128);
//    }
//    fclose($fp);


    $outArr = [
        'GET /php.php HTTP/1.1',
        'Host: www.test.com',
        'Connection: Close',
        '',
        ''
    ];
    $outStr = implode("\r\n",$outArr); //这里要注意必须为双引号

    fwrite($fp,$outStr);
    while (!feof($fp)) {
        echo fgets($fp, 128);
    }
    fclose($fp);
}